package com.mini.admin.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.mini.admin.api.dto.ListMenuParamDTO;
import com.mini.admin.api.dto.MenuPageDTO;
import com.mini.admin.api.entity.SysMenu;
import com.mini.admin.api.vo.MenuTreeVO;
import com.mini.admin.service.SysMenuService;
import com.mini.common.core.result.RestResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Zhou Feng
 */
@Api(tags = "菜单管理")
@RestController
@RequestMapping("/menu")
public class SysMenuController {
    @Autowired
    private SysMenuService menuService;

    @ApiOperation("test")
    @GetMapping("/test")
    public RestResponse<List<SysMenu>> getMenuList(@Validated @RequestBody ListMenuParamDTO param){
        LambdaQueryWrapper<SysMenu> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(SysMenu::getParentId, param.getParentId());
        List<SysMenu> res = menuService.list(wrapper);
        return RestResponse.ok(res);
    }

    @ApiOperation("获取树形菜单")
    @GetMapping("/tree")
    public RestResponse<List<MenuTreeVO>> getMenuTree(){
        return RestResponse.ok(menuService.getMenuTree());
    }

    @ApiOperation("分页查询菜单")
    @GetMapping("/page")
    public RestResponse<IPage<SysMenu>> getMenuByPage(@Validated MenuPageDTO menuPageDTO){
        return RestResponse.ok(menuService.getMenuByPage(menuPageDTO));
    }
}
